
package com.example.project3

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.widget.EditText
import android.widget.TextView
import android.widget.Button
import androidx.activity.ComponentActivity

const val FIRST_MSG = "FIRST_MSG"
const val SECOND_MSG = "SECOND_MSG"
@Suppress("DEPRECATION")
class MainActivity : ComponentActivity() {
        private lateinit var textView: TextView
        @SuppressLint("MissingInflatedId")
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)
        val first = findViewById<Button>(R.id.First)
        val editText = findViewById<EditText>(R.id.editText)
        val second = findViewById<Button>(R.id.Second)
        textView = findViewById(R.id.textView)
        val third = findViewById<Button>(R.id.third)
        val fourth = findViewById<Button>(R.id.fourth)
        first.setOnClickListener{
            val intent = Intent(this, SecondActivity::class.java)
            intent.putExtra(FIRST_MSG,editText.text.toString())
            startActivity(intent)
        }
        second.setOnClickListener{
            val intent = Intent(this, ThirdActivity::class.java)
            startActivityForResult(intent,0)
        }
        third.setOnClickListener {
            val intent = Intent(this, FourthActivity::class.java)
            startActivity(intent)
        }
        fourth.setOnClickListener {
             val intent = Intent(this, FifthActivity::class.java)
             startActivity(intent)
        }
    }

    @Deprecated("Deprecated in Java")
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if(requestCode == 0){
            if (resultCode == 1) {
                textView.text = data?.getStringExtra(SECOND_MSG)
            }
        }
    }
}
